﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

namespace JugglingMvc.Models
{
    public partial class Juggler
    {
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }
        public IEnumerable<RuleViolation> GetRuleViolations()
        {
           
                if (String.IsNullOrEmpty(Name))
                    yield return new RuleViolation("Name required", "Name");
              
                yield break;
           
        }
        partial void OnValidate(ChangeAction action)
        {
            if (!IsValid)
                throw new ApplicationException("Rule violations prevent saving (see juggler.cs)");
        }
        public class RuleViolation
        {
            public string ErrorMessage { get; private set; }
            public string PropertyName { get; private set; }
            public RuleViolation(string errorMessage)
            {
                ErrorMessage = errorMessage;
            }
            public RuleViolation(string errorMessage, string propertyName)
            {
                ErrorMessage = errorMessage;
                PropertyName = propertyName;
            }

           


        }
      
    }
   
}
